package com.itheima.skyserver.handler;

import com.itheima.skyserver.exception.BaseException;
import com.itheima.skyserver.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result exceptionHandle(Exception e) {
        log.error("服务器（系统）发生异常：{}", e.getMessage(), e);
        return Result.error("对不起,操作失败,请联系管理员");
    }

    @ExceptionHandler(BaseException.class)
    public Result exceptionBusinessHandle(BaseException e) {
        log.error("服务器（业务）发生异常：{}", e.getMessage(), e);
        return Result.error(e.getMessage());
    }
}
